<%@ page language="java" contentType="text/html; charset=UTF-8" %>


<%@ page import="java.io.File" %>

<%@ page import="java.util.List" %>

<%@ page import="com.test.SvnListTempStatic" %>
<%@ page import="com.fasterxml.jackson.databind.util.JSONPObject" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="com.component.CustomInfo" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="com.component.yhqProperties" %>
<%@ page import="cn.hutool.extra.pinyin.PinyinUtil" %>

<%!
    public static String null2String(String s) {
        return s == null ? "" : s;

    }

    public static String null2String(String s, String def) {
        return s == null ? (def == null ? "" : def) : s;

    }

    public static String null2String(Object s) {
        return s == null ? "" : s.toString();

    }
%>
<%
    /**
     * 预先保存标准文件列表
     */
    try {
        request.setAttribute("Access-Control-Allow-Origin", "*");
        response.setHeader("X-Frame-Options", "ALLOWALL");
        response.setHeader("Access-Control-Allow-Origin", "*");
        String svnlistStr = null2String(request.getParameter("svnlist"));

        WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        yhqProperties yhqProperties = (com.component.yhqProperties) context.getBean("yhqProperties");


//        处理一下没用的数据
        List<String> svnlist = Arrays.asList(svnlistStr.split(",")).stream().filter(s -> (s.contains("http") || s.contains("https") || s.contains("$"))).collect(Collectors.toList());
        svnlistStr = StringUtils.join(svnlist, ",");


        String standardinfo = null2String(request.getParameter("standardinfo"));
        String taskinfo = null2String(request.getParameter("taskinfo"));
        String customerId = null2String(request.getParameter("customerId"));




        SvnListTempStatic svnListTempStatic ;

        if (SvnListTempStatic.map.containsKey(customerId)) {
            svnListTempStatic =SvnListTempStatic.map.get(customerId);
        }else {
            svnListTempStatic = new SvnListTempStatic();

        }

        svnListTempStatic.setSvnlist(svnlistStr);
        svnListTempStatic.setStandardinfo(standardinfo);
        svnListTempStatic.setTaskinfo(taskinfo);

        String packInfoStr = null2String(request.getParameter("packInfo"));
        String customInfoStr = null2String(request.getParameter("customInfo"));

        JSONObject packInfoObject = JSONObject.fromObject(packInfoStr);
        JSONObject customInfoObject = JSONObject.fromObject(customInfoStr);
        System.out.println(customInfoObject);
        svnListTempStatic.map.put(customerId,svnListTempStatic);

        CustomInfo customInfo ;
        if (svnListTempStatic.getCustomInfo()!=null){
             customInfo = svnListTempStatic.getCustomInfo();
        }else {
             customInfo = new CustomInfo();
        }
        customInfo.setCustomerId(customInfoObject.getString("customerId"));
        customInfo.setSysVersionName(customInfoObject.getString("sysVersionName"));
        customInfo.setCustomerName(customInfoObject.getString("customerName"));
        customInfo.setDbVersion(customInfoObject.getString("dbVersion"));
        customInfo.setAsVersionName(customInfoObject.getString("asVersionName"));
        customInfo.setHistoryPath(customInfoObject.getString("sharePath") + "\\历史文件\\ecology");
        customInfo.setVmIPOA("http://"+customInfoObject.getString("vmIP")+":8080");
        customInfo.setVmIP(packInfoObject.getString("systempath"));
        customInfo.setCustomerCardUrl("https://www.e-cology.com.cn/customersystem/data/CustomerSystemRecordView.jsp?customerId="+customerId);
        customInfo.setUpgradePath(customInfoObject.getString("upgradePath"));
        customInfo.setTitle(packInfoObject.getString("title"));

        String pinyin = PinyinUtil.getPinyin(customInfo.getCustomerName().replace("（","").replace("）","").replace("(","").replace(")",""),"_").replace(" ","");

        customInfo.setLocalOa(yhqProperties.getEcologyUrl()+"\\"+pinyin);

        String svnpath = packInfoObject.getString("svnpath") + ";";
        svnpath = ToDBC(svnpath);//有的客户svn地址不规范用全角的 ； 来拼接 ec和em的svn地址

        String[] svnpathArr = svnpath.split(";");
        String mobilesvn = "";
        String ecsvn = "";

        for (String url : svnpathArr) {
            if (url.contains("Mobile")) {
                mobilesvn = url.substring(0, url.lastIndexOf("/"));
            } else {
                ecsvn = url.substring(0, url.lastIndexOf("/"));
            }
        }

        customInfo.setSvnMobilePath(mobilesvn);
        customInfo.setSvnECPath(ecsvn);
        System.out.println("customInfo = " + customInfo);

        svnListTempStatic.setCustomInfo(customInfo);


        out.print(true);
    } catch (Exception e) {
        out.print(false);
        e.printStackTrace();
    }

%>
<%!//全角转半角
    public static String ToDBC(String input) {
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char) 32;
                continue;
            }
            if (c[i] > 65280 && c[i] < 65375)
                c[i] = (char) (c[i] - 65248);
        }
        return new String(c);
    }
%>



